package com.dw.widget.slideshow.config.view.list;

import java.util.EventListener;

import com.dw.widget.slideshow.config.view.Switch;
import com.dw.widget.slideshow.R;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class ListSwitchItemView extends BaseListItemView {

	private ListItemIconView iconView;
	private TextView textView;
	private Switch switchToggle;
	private OnToggleSwitchListener switchListener;
	
	public ListSwitchItemView(Context context) {
		
		this(context, null);
	}
	
	public ListSwitchItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	protected void onFinishInflate() {

		super.onFinishInflate();

		iconView = (ListItemIconView)findViewById(R.id.listitemswitch_icon);
		textView = (TextView)findViewById(R.id.listitemswitch_text);
		switchToggle = (Switch)findViewById(R.id.listitemswitch_toggle);
		switchToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				
				if(switchListener != null)
				{
					switchListener.onSwitch(isChecked);
				}
			}
		});
	}

	public void setIconBackgroundColor(int color)
	{
		iconView.setBackgroundColor(color);
	}
	
	public void setIcon(int resId)
	{
		iconView.setIcon(resId);
	}
	
	public void setText(String text)
	{
		textView.setText(text);
	}
	
	public void setOnToggleSwitchListener(OnToggleSwitchListener listener)
	{
		switchListener = listener;
	}

	public interface OnToggleSwitchListener extends EventListener{
		
		abstract public void onSwitch(boolean on);
	}
	
	public TextView getTextView()
	{
		return textView;
	}
	
	public Switch getToggle()
	{
		return switchToggle;
	}
}
